/*
 * EnumAttribute
 * 
 * Project: Search Engine
 * 
 * Copy right 2012 by Phan Hoàn Vũ
 * Email hoanvuphan@gmail.com
 */

package hcmus.fit.ml.tr.data;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * @author hvp
 * 
 */
public class EnumAttribute extends DefaultAttribute implements Attribute {

    
    private List<Object> enums;

    public EnumAttribute(String name, String predefinedEnum) {
        this.setName(name);
        this.enums = new ArrayList<Object>(Arrays.asList(predefinedEnum.replace("{", "")
                .replace("}", "").trim().replace(" ", "").toUpperCase().split(",")));
    }

    /**
     * {@inheritDoc}
     */
    public Object parseValue(String value) {
        if(!enums.contains(value.toUpperCase())) {
            throw new IllegalArgumentException("The given value is not pre-defined: " + value);
        }
        return value.toUpperCase();
    }

    public List<Object> getEnums() {
        return enums;
    }
}
